﻿// Testing.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include "../dxrRender/dxrRender.h"
#include <iostream>

int main()
{
    std::vector<MeshData*> meshes;
    std::vector<InstanceData*> instances;

    dxrInitSystem();
    dxrCreateRenderTarget();
    dxrUpdateRenderTarget(nullptr, 512, 512, RenderTargetFormat::RGBAu8);
    LightData* light = dxrCreateLight();
    dxrUpdateLight(light, float3{ 1,1,1 });

    dxrCreateCamera();
    dxrUpdateCameraTransform({ 0,0,0 }, float4x4::identity(), float4x4::identity());

    // create meshes
    {
        // standing triangle
        static const float3 vertices[]{
            {-1.0f, 0.0f, 0.0f},
            { 1.0f, 0.0f, 0.0f},
            { 0.0f, 2.0f, 0.0f},
        };
        static const int indices[]{
            0, 1, 2,
        };
        auto* triangle = dxrCreateMesh();
        dxrUpdateCPUMesh(triangle, vertices, indices, sizeof(float3), _countof(vertices), 0, sizeof(int), _countof(indices), 0);
        meshes.push_back(triangle);

        // add a instance with default transform (identity matrix)
        auto instance = dxrCreateInstance(triangle);
        instances.push_back(instance);
    }
    {
        // floor quad
        static const float3 vertices[]{
            {-5.0f, 0.0f, 5.0f},
            { 5.0f, 0.0f, 5.0f},
            { 5.0f, 0.0f,-5.0f},
            {-5.0f, 0.0f,-5.0f},
        };
        static const int indices[]{
            0, 1, 2, 0, 2, 3,
        };
        auto* quad = dxrCreateMesh();
        meshes.push_back(quad);
        dxrUpdateCPUMesh(quad, vertices, indices, sizeof(float3), _countof(vertices), 0, sizeof(int), _countof(indices), 0);

        // add a instance with default transform
        auto instance = dxrCreateInstance(quad);
        instances.push_back(instance);
    }

    dxrRender();


    for (auto v : instances)
    {
        dxrRemoveInstance(v);
    }
    instances.clear();

    for (auto v : meshes)
    {
        dxrRemoveMesh(v);
    }
    meshes.clear();
    
    dxrRemoveCamera();
    dxrRemoveLight(light);
    dxrRemoveRenderTarget();

    dxrUnInitSystem();
    std::cout << "Hello World!\n";
}

